﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using BusinessModel;
using EntityDataModel;
using System.ComponentModel;
using System.Data.Objects.DataClasses;

namespace Controller.DataProvider
{
    public class SaleOrderDetailPro : GenericProvider<SaleOrderDetail>
    {
        public SaleOrderDetailPro()
        {
            EntityName = "Tbl_SaleOrderDetail";
        }

        #region override Methods
        //----------------------------------------
        public override EntityObject CreateEntity()
        {
            return new Tbl_SaleOrderDetail();
        }
        //----------------------------------------
        public override SaleOrderDetail CreateModel()
        {
            return new SaleOrderDetail();
        }
        //----------------------------------------
        public override void ToEntity(SaleOrderDetail pModel, EntityObject pEntity, params EnumFieldCopy[] pEnumFieldCopys)
        {
            Tbl_SaleOrderDetail oEntity = pEntity as Tbl_SaleOrderDetail;
            oEntity.SaleOrderId = pModel.SaleOrderId;
            oEntity.ProductId = pModel.ProductId;
            oEntity.UnitId = pModel.UnitId;
            oEntity.Quantity = pModel.Quantity;
            oEntity.SalePriceUnit = pModel.SalePriceUnit;
            pEnumFieldCopys.ToList().ForEach((item) =>
            {
                switch (item)
                {
                    case EnumFieldCopy.Id:
                        oEntity.Id = pModel.Id;
                        break;
                    case EnumFieldCopy.All:
                        oEntity.Id = pModel.Id;
                        break;
                }
            });
        }
        //----------------------------------------
        public override void ToModel(EntityObject pEntity, SaleOrderDetail pModel, params EnumFieldCopy[] pEnumFieldCopys)
        {
            Tbl_SaleOrderDetail oEntity = pEntity as Tbl_SaleOrderDetail;
            pModel.SaleOrderId = oEntity.SaleOrderId;
            pModel.ProductId = oEntity.ProductId;
            pModel.UnitId = oEntity.UnitId;
            pModel.Quantity = oEntity.Quantity;
            pModel.SalePriceUnit = oEntity.SalePriceUnit;
            pEnumFieldCopys.ToList().ForEach((item) =>
            {
                switch (item)
                {
                    case EnumFieldCopy.Id:
                        pModel.Id = oEntity.Id;
                        break;
                    case EnumFieldCopy.All:
                        pModel.Id = oEntity.Id;
                        break;
                }
            });
        }
        #endregion override Methods
    }
}
